#include "MessageServer.h"



void MessageServer::StartAccept()
{
	Session *newSession = new Session(ioService_, &messages);
	acceptor_.async_accept(newSession->Socket(),
		boost::bind(&MessageServer::HandleAccept, this, newSession,
		boost::asio::placeholders::error));
}

void MessageServer::HandleAccept(Session *newSession,
	const boost::system::error_code &error)
{
	if (!error)
	{
		newSession->Start();
	}
	else
	{
		delete newSession;
	}

	StartAccept();
}

MessageServer::MessageServer(boost::asio::io_service &ioService, short port)
: ioService_(ioService),
acceptor_(ioService, tcp::endpoint(tcp::v4(), port))
{
	StartAccept();
}




